<template>
  <div style="padding: 10px">
    <!-- 按钮区域 -->

    <!-- 搜索框区域 -->

    <div style="margin: 10px 0">
      <el-input
        v-model="search"
        placeholder="请输入管理员名字"
        clearable
        style="width: 20%"
      />
      <el-button type="primary" style="margin-left: 10px" @click="findAll"
        >查询</el-button
      >
    </div>

    <!-- 表单区域开始 -->
    <el-table :data="tableData" border stripe style="width: 100%">
      <el-table-column
        prop="id"
        label="ID"
        sortable
        width="80"
      ></el-table-column>
      <el-table-column
        prop="username"
        label="用户名"
        width="120"
      ></el-table-column>

      <el-table-column
        prop="account"
        label="账号"
        width="180"
      ></el-table-column>
      <el-table-column prop="loginTime" label="登录时间"
      width="280px" ></el-table-column>
      <el-table-column
        prop="loginState"
        label="登录状态"
        sortable
      ></el-table-column>
      <el-table-column
        prop="memo"
        label="登录详情"
      ></el-table-column>
       <el-table-column
        prop="role"
        label="登录角色"
      ></el-table-column>
    </el-table>
    <!-- 表单区域结束 -->

    <!-- 分页开始 -->
    <div style="margin: 10px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        v-model:currentPage="pageNum"
        :page-sizes="[5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    <!-- 分页结束 -->
  </div>
</template>

<script>
import request from "../../utils/request";

export default {
  name: "Manager",
  components: {},
  data() {
    return {
      search: null, //定义输入框
      currentPage: 1, //默认是1
      pageSize: 10, //默认为10
      pageNum: 1,
      total: 0,
      dialogVisible: false, //默认关闭 (添加用户弹出框)
      form: {}, //定义form对象为空
      tableData: [],
      sex: 0,
      drawer: false, //默认不显示抽屉
    };
  },
  //页面加载时
  created() {
    this.findAll();
  },

  //方法写在data外面
  methods: {
    //查询所有用户
    findAll() {
      console.log(this.search);
      request
        .get("/login-log/findAll", {
          params: {
            //传入变量
            pageSize: this.pageSize,
            pageNum: this.pageNum,
            username: this.search,
          },
        })
        .then((res) => {
          console.log(res);
          //重点 将查询到的数据records 返回给表单中的tableData
          (this.tableData = res.data.list), (this.total = res.data.total);
        });
    },

    //改变条数
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.findAll();
    },

    //改变当前页码
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum;
      this.findAll();
    },
  },
};
</script>
